<template>
	<view class="pageV">
		<u-navbar title="常用地址" placeholder :autoBack="true" leftIconColor="#E6A5B4" bgColor="#000000"
			:titleStyle="titleStyle">
		</u-navbar>
		<view class="centV">
			<view @click="onItemClick(item)" class="itemV" v-for="(item,index) in listData" :key="index">
				<view class="itemLeftV">
					<view class="itemTv1">{{item.name}} {{item.mobile}}</view>
					<view class="itemTv2">{{item.province.name}} {{item.city.name}} {{item.area.name}} {{item.address}}
					</view>
					<view class="itemTv3" v-if="item.is_default==1">默认地址</view>
				</view>
				<image @click.stop="onEtClick(item)" class="itemIv" src="https://s1.ax1x.com/2023/04/20/p9AlLL9.png">
				</image>
			</view>
			<view class="noDataV" v-if="listData.length==0">
				<image class="noDataIv" src="https://s1.ax1x.com/2023/04/20/p9A8YxU.png"></image>
				<view class="noDataTv">暂无地址</view>
			</view>
		</view>
		<view class="bottomV">
			<view class="bottomTv" @click="onAddClick()">新增地址</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				titleStyle: {
					"color": "#ffffff"
				},
				listData: [],
				type: null,
			}
		},
		onLoad(e) {
			this.type = e.type;
		},
		onShow() {
			this.getShopAddress();
		},
		methods: {
			onItemClick(item) {
				if (this.type === "selete") {
					let pages = getCurrentPages()
					let prevPage = pages[pages.length - 2] //上一页页面实例
					uni.navigateBack({
						delta: 1,
						success: () => {
							prevPage.$vm.otherFun(JSON.stringify(item)) // 给上一页绑定方法otherFun,传参地址id
						}
					})
				}
			},
			getShopAddress() {
				this.$api.getShopAddress({

				}).then((res) => {
					this.listData = res;
				}).catch((e) => {
					uni.$u.toast(e.msg === undefined ? "获取失败" : e.msg)
				})
			},
			onEtClick(item) {
				this.$u.route({
					url: "/shop/addressAdd/addressAdd",
					params: {
						id: item.id,
					}
				})
			},
			onAddClick() {
				this.$u.route({
					url: "/shop/addressAdd/addressAdd",
				})
			}
		}
	}
</script>

<style>
	.pageV {
		width: 100%;
		min-height: 100vh;
		display: flex;
		flex-direction: column;
	}

	.centV {
		width: 100%;
		padding-bottom: 160rpx;
	}

	.itemV {
		background: #383838;
		border-radius: 10rpx;
		padding: 30rpx;
		box-sizing: border-box;
		display: flex;
		align-items: center;
		margin-left: 30rpx;
		margin-right: 30rpx;
		margin-bottom: 30rpx;
	}

	.itemLeftV {
		display: flex;
		flex-direction: column;
		flex: 1;
		padding-right: 20rpx;
	}

	.itemTv1 {
		font-size: 32rpx;
		color: #FFFFFF;
	}

	.itemTv2 {
		font-size: 32rpx;
		color: #FFFFFF;
		margin-top: 30rpx;
	}

	.itemTv3 {
		font-size: 32rpx;
		color: #E6A5B4;
		margin-top: 30rpx;
	}

	.itemIv {
		width: 40rpx;
		height: 40rpx;
	}

	.bottomV {
		height: 160rpx;
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: center;
		position: fixed;
		bottom: 0;
	}

	.bottomTv {
		width: 100%;
		height: 100rpx;
		background: #E6A5B4;
		border-radius: 10rpx;
		text-align: center;
		font-size: 32rpx;
		color: #333737;
		margin-left: 30rpx;
		margin-right: 30rpx;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.noDataV {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		margin-top: 220rpx;
	}

	.noDataIv {
		width: 250rpx;
		height: 250rpx;
	}

	.noDataTv {
		margin-top: 30rpx;
		font-size: 32rpx;
		color: #939393;
	}
</style>
